#!/usr/bin/env python3.11
# -*- encoding: utf-8 -*-
'''
@File    :   permissions.py
@Time    :   2024/02/22 08:31:09
@Author  :   windstarry 
@Version :   1.0
'''
# here put the import lib
from django.http import HttpRequest
from ninja_extra.permissions.base import BasePermission
from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from ninja_extra.controllers.base import ControllerBase


    
class IsRoleUser(BasePermission):
    """
    Allows access only to role user.
    """

    def has_permission(
        self, request: HttpRequest, controller: "ControllerBase"
    ) -> bool:
        user = request.user or request.auth
        return bool(user and user.role == "teacher")